package com.gx.util.core.core;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class EdtitionMethod {
    private static final Logger log = LoggerFactory.getLogger(EdtitionMethod.class);
    public static Map<String, Map<String, ActionMethod>> versionMethodMap = new ConcurrentHashMap<String, Map<String, ActionMethod>>();


    public static Map<String, ActionMethod> getMethodMap(String version) {
        return versionMethodMap.get(version);
    }

    /**
     * put版本的一个方法
     *
     * @param version
     * @param methodName
     * @param actionMethod
     */
    public static void putMethodMap(String version, String methodName, ActionMethod actionMethod) throws Exception {
        Map<String, ActionMethod> map = versionMethodMap.get(version);
        if (map == null) {
            map = new ConcurrentHashMap<>();
            versionMethodMap.put(version, map);
        }
		if (map.containsKey(methodName)){
			log.error("方法名出现重复版本为  {}  方法为  {}  ",version,methodName);
			throw new  Exception("方法名出现重复版本为");
		}
        versionMethodMap.get(version).put(methodName, actionMethod);
    }

    /**
     * put版本的所有方法
     *
     * @param map
     * @param version
     */
    public static void putVersionMethodMap(Map<String, ActionMethod> map, String version) {
        versionMethodMap.put(version, map);
    }


}
